import { saveAs } from 'file-saver'
import * as XLSX from 'xlsx'
export const filesExport = (allList, name) => {
    const ws = XLSX.utils.json_to_sheet(
        allList
    )
    const wb = XLSX.utils.book_new()
    XLSX.utils.book_append_sheet(wb, ws, name)

    const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' })
    saveAs(new Blob([wbout], { type: 'application/octet-stream' }), `${name}.xlsx`)
}


export const filesDown = (url) => {
    const a = document.createElement('a')
    a.href = url // a链接的下载地址
    a.setAttribute('download', 0) // 把a标签设置为下载，并为文件取名
    document.body.appendChild(a) // 把a链接插入到结构中
    a.click() // 自动点击触发下载
    // 下载完成后，记得移除a标签和释放生成的下载链接
    document.body.removeChild(a)
}